package com.gitee.huxing.course.publish;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gitee.huxing.course.domain.module.PlatFormOrderDO;
import com.gitee.huxing.course.service.StockService;
import com.gitee.huxing.framework.redis.MessageHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.publish
 * @ClassName: MessageSubscriber
 * @Author: huxing
 * @DateTime: 2021-10-26 下午2:32
 */
@Slf4j
@Service("messageHandler")
public class MessageSubscriber implements MessageHandler {

    @Autowired
    StockService service;

    @Override
    public void handler(String message) {
        // 收到消息的处理逻辑
        Object obj = JSON.parse(message);
        // 处理订单库存
        PlatFormOrderDO order = JSONObject.parseObject(obj.toString(), PlatFormOrderDO.class);
        // 库存减少
        this.service.reduce(order.getProductId());
    }
}
